const _function = require("../../utils/functionData.js")
Page({
  data: {
    activity: {
      // id: 1,
      // cover: 'https://example.com/activity1-cover.jpg',
      // title: 'JavaScript入门讲座',
      // time: '2023-10-15 14:00',
      // location: '教学楼A101',
      // description: '本次讲座将带你快速入门JavaScript，掌握基础知识。',
      // isJoined: false
    },
    isJoin:false,
    activityId: null,
    _UrlGet_: wx.getStorageSync('img_url')
  },
  onLoad(options) {
    this.setData({
      activityId: options.id
    })
    this.getStudentActivityList()
    this.getActivitiesDetail()
  },
  getActivitiesDetail() {
    console.log('获取社团详情');
    // const prams = {
    //   chatId: this.data.chatId,
    //   speak_user: getApp().globalData.userInfo.role
    // }
    _function.getActivitiesDetail(this.data.activityId, '', this.getActivitiesDetailBack, this)
  },
  getActivitiesDetailBack(res) {
    let dataAll = res.data
    if (dataAll.code == 200) {
      this.setData({
        activity: dataAll.data
      })
      // this.getSocietyActivitiesList()
      console.log('消息列表', dataAll.data);
    }
  },
  // 报名
  joinActivity: function () {
    if(this.data.isJoin){
      return
    }
    const params = {
      studentId: getApp().globalData.userInfo.userId,
      activityId: this.data.activityId
    }
    _function.postStudentActivity(params, this.postStudentActivityBack, this)
  },
  postStudentActivityBack(res) {
    let dataAll = res.data
    if (dataAll.code == 200) {
      this.getStudentActivityList()
      this.getActivitiesDetail()
      wx.showToast({
        title: '报名成功',
        icon: 'none', 
        duration: 1500, 
        mask: true, 
        success: () => {
        }
      });
    }
  },


  getStudentActivityList() {
    console.log('获取社团详情');
    const prams = {
      activityId: this.data.activityId,
      studentId: getApp().globalData.userInfo.userId
    }
    _function.getStudentActivityList(prams, this.getStudentActivityListBack, this)
  },
  getStudentActivityListBack(res) {
    let dataAll = res.data
    if (dataAll.code == 200) {
      if (dataAll.rows.length > 0) {
        this.setData({
          isJoin: true
        })
      }
      // this.getSocietyActivitiesList()
      console.log('消息列表', dataAll.data);
    }
  },
});